home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / ToolManager / Source / Prefs / cliplist.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  9KB  |  339 lines

  1. /*
  2.  * cliplist.c  V3.1
  3.  *
  4.  * Class for TM objects clipboard window
  5.  *
  6.  * Copyright (C) 1990-98 Stefan Becker
  7.  *
  8.  * This source code is for educational purposes only. You may study it
  9.  * and copy ideas or algorithms from it for your own projects. It is
  10.  * not allowed to use any of the source codes (in full or in parts)
  11.  * in other programs. Especially it is not allowed to create variants
  12.  * of ToolManager or ToolManager-like programs from this source code.
  13.  *
  14.  */
  15.  
  16. #include "toolmanager.h"
  17.  
  18. /* Local data */
  19. static const char *TextColumnName;
  20. static const char *TextColumnType;
  21.  
  22. /* ClipList class instance data */
  23. struct ClipListClassData {
  24.  struct Hook clcd_Construct;
  25. };
  26. #define TYPED_INST_DATA(cl, o) ((struct ClipListClassData *) INST_DATA((cl), (o)))
  27.  
  28. /* ClipList class construct function */
  29. #undef  DEBUGFUNCTION
  30. #define DEBUGFUNCTION ClipListClassConstruct
  31. __geta4 static ULONG ClipListClassConstruct(__a0 struct Hook *h,
  32.                                             __a1 Object *obj)
  33. {
  34.  /* Attach to object */
  35.  return((ULONG) DoMethod(obj, TMM_Attach, h->h_Data));
  36. }
  37.  
  38. /* ClipList class destruct function */
  39. #undef  DEBUGFUNCTION
  40. #define DEBUGFUNCTION ClipListClassDestruct
  41. __geta4 static void ClipListClassDestruct(__a1 struct AttachData *ad)
  42. {
  43.  /* Detach from object if not a notify event */
  44.  if (ad->ad_Object) DoMethod(ad->ad_Object, TMM_Detach, ad);
  45. }
  46.  
  47. /* ClipList class display function */
  48. #undef  DEBUGFUNCTION
  49. #define DEBUGFUNCTION ClipListClassDisplay
  50. __geta4 static void ClipListClassDisplay(__a1 struct AttachData *ad,
  51.                                          __a2 const char **array)
  52. {
  53.  /* Entry valid? */
  54.  if (ad) {
  55.   ULONG type;
  56.  
  57.   /* Yes, get object name */
  58.   GetAttr(TMA_Name, ad->ad_Object,  (ULONG *) array++);
  59.  
  60.   /* Get object type */
  61.   GetAttr(TMA_Type, ad->ad_Object,  &type);
  62.  
  63.   /* Set second column text according to object type */
  64.   switch (type) {
  65.    case TMOBJTYPE_EXEC:  *array = TextGlobalExecObject;  break;
  66.    case TMOBJTYPE_IMAGE: *array = TextGlobalImageObject; break;
  67.    case TMOBJTYPE_SOUND: *array = TextGlobalSoundObject; break;
  68.   }
  69.  
  70.  } else {
  71.  
  72.   /* No, create title column */
  73.   *array++ = TextColumnName;
  74.   *array   = TextColumnType;
  75.  }
  76. }
  77.  
  78. /* Hooks */
  79. static const struct Hook DestructHook = {
  80.  {NULL, NULL}, (void *) ClipListClassDestruct, NULL, NULL
  81. };
  82. static const struct Hook DisplayHook = {
  83.  {NULL, NULL}, (void *) ClipListClassDisplay, NULL, NULL
  84. };
  85.  
  86. /* ClipList class method: OM_NEW */
  87. #define DEBUGFUNCTION ClipListClassNew
  88. static ULONG ClipListClassNew(Class *cl, Object *obj, struct opSet *ops)
  89. {
  90.  CLIPLIST_LOG((LOG1(Tags, "0x%08lx", ops->ops_AttrList),
  91.                PrintTagList(ops->ops_AttrList)))
  92.  
  93.  /* Create object */
  94.  if (obj = (Object *) DoSuperNew(cl, obj,
  95.                                  MUIA_List_DestructHook,  &DestructHook,
  96.                                  MUIA_List_DisplayHook,   &DisplayHook,
  97.                                  MUIA_List_Format,        "BAR,",
  98.                                  MUIA_List_ShowDropMarks, FALSE,
  99.                                  MUIA_List_Title,         TRUE,
  100.                                  TAG_MORE,               ops->ops_AttrList)) {
  101.   struct ClipListClassData *clcd = TYPED_INST_DATA(cl, obj);
  102.  
  103.   /* Initialize construct hook */
  104.   clcd->clcd_Construct.h_Entry = (void *) ClipListClassConstruct;
  105.   clcd->clcd_Construct.h_Data  = obj;
  106.  
  107.   /* Set construct hook */
  108.   SetAttrs(obj, MUIA_List_ConstructHook, &clcd->clcd_Construct, TAG_DONE);
  109.  }
  110.  
  111.  CLIPLIST_LOG(LOG1(Result, "0x%08lx", obj))
  112.  
  113.  /* Return pointer to created object */
  114.  return((ULONG) obj);
  115. }
  116.  
  117. /* ClipList class method: OM_GET */
  118. #undef  DEBUGFUNCTION
  119. #define DEBUGFUNCTION ClipListClassGet
  120. static ULONG ClipListClassGet(Class *cl, Object *obj, struct opGet *opg)
  121. {
  122.  ULONG rc;
  123.  
  124.  CLIPLIST_LOG(LOG2(Attribute, "0x%08lx (%s)", opg->opg_AttrID,
  125.                    GetTagName(opg->opg_AttrID)))
  126.  
  127.  /* Which attribute is requested? */
  128.  switch(opg->opg_AttrID) {
  129.   case TMA_Active: {
  130.     struct AttachData *ad;
  131.  
  132.     /* Get active entry */
  133.     DoMethod(obj, MUIM_List_GetEntry, MUIV_List_GetEntry_Active,
  134.              (ULONG *) &ad);
  135.  
  136.     /* If active entry is valid return pointer to attached object */
  137.     *opg->opg_Storage = (ULONG) (ad ? ad->ad_Object : NULL);
  138.  
  139.     /* Return TRUE to indicate that the attribute is implemented */
  140.     rc = TRUE;
  141.    }
  142.    break;
  143.  
  144.   default:
  145.    rc = DoSuperMethodA(cl, obj, (Msg) opg);
  146.    break;
  147.  }
  148.  
  149.  CLIPLIST_LOG(LOG2(Result, "%ld value 0x%08lx", rc, *opg->opg_Storage))
  150.  
  151.  return(rc);
  152. }
  153.  
  154. /* ClipList class method: MUIM_DragQuery */
  155. #undef  DEBUGFUNCTION
  156. #define DEBUGFUNCTION ClipListClassDragQuery
  157. static ULONG ClipListClassDragQuery(Class *cl, Object *obj,
  158.                                     struct MUIP_DragQuery *mpdq)
  159. {
  160.  ULONG rc = MUIV_DragQuery_Refuse;
  161.  
  162. #if DEBUG_VERY_NOISY
  163.  /* This just generates too much debug output... */
  164.  CLIPLIST_LOG(LOG2(Arguments, "Object 0x%08lx Source 0x%08lx", obj,
  165.                    mpdq->obj))
  166. #endif
  167.  
  168.  /* Is source our list? */
  169.  if (mpdq->obj != obj) {
  170.   Object *active;
  171.   ULONG   type   = TMOBJTYPES;
  172.  
  173.   /* No, get active entry */
  174.   if (GetAttr(TMA_Active, mpdq->obj, (ULONG *) &active))
  175.  
  176.    /* Get type of object */
  177.    GetAttr(TMA_Type, active, &type);
  178.  
  179.   /* Check type, only Exec, Image and Sound objects are accepted */
  180.   if (type <= TMOBJTYPE_SOUND) rc = MUIV_DragQuery_Accept;
  181.  }
  182.  
  183.  return(rc);
  184. }
  185.  
  186. /* ClipList class method: MUIM_DragDrop */
  187. #undef  DEBUGFUNCTION
  188. #define DEBUGFUNCTION ClipListClassDragDrop
  189. static ULONG ClipListClassDragDrop(Class *cl, Object *obj,
  190.                                    struct MUIP_DragDrop *mpdd)
  191. {
  192.  Object *active;
  193.  
  194.  /* Get active entry */
  195.  GetAttr(TMA_Active, mpdd->obj, (ULONG *) &active);
  196.  
  197.  CLIPLIST_LOG(LOG1(Object, "0x%08lx", active))
  198.  
  199.  /* Insert object */
  200.  DoMethod(obj, MUIM_List_InsertSingle, active, MUIV_List_Insert_Bottom);
  201.  
  202.  /* Return 1 to indicate that the method is implemented */
  203.  return(1);
  204. }
  205.  
  206. /* ClipList class method: TMM_Notify */
  207. #undef  DEBUGFUNCTION
  208. #define DEBUGFUNCTION ClipListClassNotify
  209. static ULONG ClipListClassNotify(Class *cl, Object *obj,
  210.                                  struct TMP_Notify *tmpn)
  211. {
  212.  int                i  = -1;
  213.  struct AttachData *ad;
  214.  
  215.  CLIPLIST_LOG(LOG2(Arguments, "Attach 0x%08lx Object 0x%08lx",
  216.                    tmpn->tmpn_Data, tmpn->tmpn_Data->ad_Object))
  217.  
  218.  /* For each entry in list */
  219.  do {
  220.  
  221.   /* Get next entry */
  222.   DoMethod(obj, MUIM_List_GetEntry, ++i, &ad);
  223.  
  224.   CLIPLIST_LOG(LOG1(Next entry, "0x%08lx", ad))
  225.  
  226.   /* AttachData found? */
  227.   if (ad == tmpn->tmpn_Data) {
  228.    ULONG method;
  229.  
  230.    /* Object deleted? Yes, remove entry, otherwise redraw it */
  231.    method = (tmpn->tmpn_Data->ad_Object == NULL) ? MUIM_List_Remove :
  232.                                                    MUIM_List_Redraw;
  233.  
  234.    CLIPLIST_LOG(LOG1(Method, "0x%08lx", method))
  235.  
  236.    /* Call method */
  237.    DoMethod(obj, method, i);
  238.  
  239.    /* Leave loop */
  240.    break;
  241.   }
  242.  
  243.  } while (ad);
  244.  
  245.  /* Return 1 to indicate that the method is implemented */
  246.  return(1);
  247. }
  248.  
  249. /* ClipList class method: TMM_DoubleClicked */
  250. #undef  DEBUGFUNCTION
  251. #define DEBUGFUNCTION ClipListClassDoubleClicked
  252. static ULONG ClipListClassDoubleClicked(Class *cl, Object *obj)
  253. {
  254.  struct AttachData *ad;
  255.  
  256.  CLIPLIST_LOG(LOG0(Entry))
  257.  
  258.  /* Get active entry */
  259.  DoMethod(obj, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &ad);
  260.  
  261.  /* Call Edit method on the object */
  262.  DoMethod(ad->ad_Object, TMM_Edit, NULL);
  263.  
  264.  /* Return 1 to indicate that the method is implemented */
  265.  return(1);
  266. }
  267.  
  268. /* ClipList class method dispatcher */
  269. #undef  DEBUGFUNCTION
  270. #define DEBUGFUNCTION ClipListClassDispatcher
  271. __geta4 static ULONG ClipListClassDispatcher(__a0 Class *cl, __a2 Object *obj,
  272.                                              __a1 Msg msg)
  273. {
  274.  ULONG rc;
  275.  
  276.  CLIPLIST_LOG(LOG3(Arguments, "Class 0x%08lx Object 0x%08lx Msg 0x%08lx",
  277.                    cl, obj, msg))
  278.  
  279.  switch(msg->MethodID) {
  280.   /* BOOPSI methods */
  281.   case OM_NEW:
  282.    rc = ClipListClassNew(cl, obj, (struct opSet *) msg);
  283.    break;
  284.  
  285.   case OM_GET:
  286.    rc = ClipListClassGet(cl, obj, (struct opGet *) msg);
  287.    break;
  288.  
  289.   /* MUI methods */
  290.   case MUIM_DragQuery:
  291.    rc = ClipListClassDragQuery(cl, obj, (struct MUIP_DragQuery *) msg);
  292.    break;
  293.  
  294.   case MUIM_DragDrop:
  295.    rc = ClipListClassDragDrop(cl, obj, (struct MUIP_DragDrop *) msg);
  296.    break;
  297.  
  298.   /* TM methods */
  299.   case TMM_Notify:
  300.    rc = ClipListClassNotify(cl, obj, (struct TMP_Notify *) msg);
  301.    break;
  302.  
  303.   case TMM_DoubleClicked:
  304.    rc = ClipListClassDoubleClicked(cl, obj);
  305.    break;
  306.  
  307.   /* Unknown method -> delegate to SuperClass */
  308.   default:
  309.    rc = DoSuperMethodA(cl, obj, msg);
  310.    break;
  311.  }
  312.  
  313.  return(rc);
  314. }
  315.  
  316. /* Create ClipList class */
  317. #undef  DEBUGFUNCTION
  318. #define DEBUGFUNCTION CreateClipListClass
  319. struct MUI_CustomClass *CreateClipListClass(void)
  320. {
  321.  struct MUI_CustomClass *rc;
  322.  
  323.  /* Create class */
  324.  if (rc = MUI_CreateCustomClass(NULL, MUIC_List, NULL,
  325.                                 sizeof(struct ClipListClassData),
  326.                                 ClipListClassDispatcher)) {
  327.  
  328.   /* Localize strings */
  329.   TextColumnName = TranslateString(LOCALE_TEXT_CLIPLIST_COLUMN_NAME_STR,
  330.                                    LOCALE_TEXT_CLIPLIST_COLUMN_NAME);
  331.   TextColumnType = TranslateString(LOCALE_TEXT_CLIPLIST_COLUMN_TYPE_STR,
  332.                                    LOCALE_TEXT_CLIPLIST_COLUMN_TYPE);
  333.  }
  334.  
  335.  CLIPLIST_LOG(LOG1(Result, "0x%08lx", rc))
  336.  
  337.  return(rc);
  338. }
  339.